/*******************************************************************************
 *  Dice Roller 2 is a tabletop rpg dice roll utility tool
 *     Copyright (C) 2014, 2015 David Meersteiner
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *     
 *     Contact me under:
 *     
 *     dmeersteiner@gmail.com
 *     
 *     David Meersteiner
 *     Am Hang 10
 *     94253 Bischofsmais
 *     GERMANY
 *******************************************************************************/
package de.dm.dr2.data.consolemessages;

import de.dm.dr2.data.diceexpressions.DiceExpression;
import de.dm.dr2.data.util.Constants;
import de.dm.dr2.data.util.RollReturn;
import de.dm.dr2.data.util.UtilFunction;

/**
 * 
 * A formatted roll of a {@code DiceExpression}.
 * 
 * @author D. Meersteiner
 * @see ConsoleMessage
 * @see DiceExpression
 */
public class DiceRollMessage extends ConsoleMessage {
	
	private String message;
	private String value;
	
	/**
	 * Creates a new formated message from a {@code DiceExpression}.
	 * 
	 * <p>When the {@code DiceRollMessage} is created, a {@code RollReturn} gets
	 * generated by {@link DiceExpression#roll()} and is used in the message.
	 * @author D. Meersteiner
	 * @param expression - the {@code DiceExpression} that will be formatted and rolled
	 * @see DiceExpression
	 */
	public DiceRollMessage(DiceExpression expression) {
		RollReturn roll = expression.roll();
		value = UtilFunction.doubleToStringWithMinimumPrecision(roll.getValue());
		message = "Rolling "+expression.toString()+":"
				+Constants.NEW_LINE
				+roll.getMessage()+" = "
				+value
				+Constants.NEW_LINE+Constants.NEW_LINE;
	}
	
	@Override
	public String getMessage() {
		return message;
	}

	@Override
	public String getValue() {
		return value;
	}
	
}
